package com.wyl.proxy.demo03

import java.lang.reflect.Proxy

fun <T> Any.getProxy(): T {
    val clazz = this::class.java
    return Proxy.newProxyInstance(
        clazz.classLoader, clazz.interfaces
    ) { _, method, args: Array<out Any>? ->
        test()
        if (args != null) {
            method.invoke(this, *args)
        } else {
            method.invoke(this)
        }
    } as T
}

private fun test() {
    println("Test")
}